#include "pairdialog.h"
#include "ui_pairdialog.h"
#include <QDialogButtonBox>


PairDialog::PairDialog(QWidget* parent) :
    QDialog(parent),
    ui(new Ui::PairDialog)
{
    ui->setupUi(this);
    this->hide();
    connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
    connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
}

PairDialog::~PairDialog()
{
    delete ui;
}


int PairDialog::showConfirmation(quint8 pinCode, const QString name, const QString& passKey)
{
    ui->pairDevice->setText(name);
    this->pinCode = pinCode;
    if(pinCode & 0x00)
    {
        ui->title->setText("确认蓝牙配对码");
        ui->pairCode->setVisible(true);
        ui->pairCode->setText(passKey);
    }
    else if(pinCode & 0x01)
    {
        ui->title->setText("确认蓝牙设备密钥");
        ui->pairCode->setVisible(true);
        ui->pairCode->setText(passKey);
    }
    else if(pinCode & 0x02)
    {
        ui->title->setText("是否进行蓝牙配对？");
        ui->pairCode->setVisible(true);
        ui->pairCode->setText(passKey);
    }
    else if(pinCode & 0x04)
    {
        ui->title->setText("是否认证蓝牙设备？");
        ui->pairCode->setVisible(false);
    }
    else if(pinCode & 0x08)
    {
        ui->title->setText("是否断开设备连接");
        ui->pairCode->setVisible(false);
        //err
    }
    return exec();
}
